package org.reference.generic.operator;

import java.util.List;

import org.reference.generic.base.Parameter;

import util.Log;


/**
 * 
 */
public class Div extends Function {

    /**
     * 
     */
    public Div(Parameter parameters) {
    	super(parameters);
    	setName("/");
    }

	@Override
    public void calc(List<Double> results) {
		//실제 연산
		while(1 < results .size()) {
			results.set(0, results.get(0) / results.get(1));
			results.remove(1);
		}
		
		//예외처리
		if (Double.isNaN(results.get(0))){
			results.set(0, 0d);
		} else if(Double.isInfinite(results.get(0))) { 
			results.set(0, 0d/*Double.MAX_VALUE*/);
		}
		Log.debug("나누기 "+results.get(0));
    }
}